package com.example.hosptial.service.impl;

import com.example.hosptial.model.view.WardStatusView;
import com.example.hosptial.model.view.WardBedPatientView;
import com.example.hosptial.repository.WardStatusRepository;
import com.example.hosptial.repository.WardBedPatientViewRepository;
import com.example.hosptial.service.WardStatusService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 病房状态服务实现类
 */
@Service
@RequiredArgsConstructor
public class WardStatusServiceImpl implements WardStatusService {

    private final WardStatusRepository wardStatusRepository;
    private final WardBedPatientViewRepository wardBedPatientViewRepository;

    @Override
    public List<Integer> getFloorsByDeptId(Integer deptId) {
        return wardStatusRepository.findFloorsByDeptId(deptId);
    }

    @Override
    public List<WardStatusView> getWardsByDeptIdAndFloor(Integer deptId, Integer floorNum) {
        return wardStatusRepository.findByDeptIdAndFloorNumOrderByWardNumAsc(deptId, floorNum);
    }

    @Override
    public List<WardStatusView> getAllWardsByDeptId(Integer deptId) {
        return wardStatusRepository.findByDeptIdOrderByFloorNumAscWardNumAsc(deptId);
    }

    @Override
    public List<WardBedPatientView> getWardBedDetails(Integer wardId) {
        if (wardId == null || wardId <= 0) {
            throw new IllegalArgumentException("无效的病房ID");
        }
        return wardBedPatientViewRepository.findByWardId(wardId);
    }
} 